<?php 
namespace phpexcel;

require_once PHPEXCEL . 'phpexcel/PHPExcel/IOFactory.php';
require_once PHPEXCEL . 'phpexcel/PHPExcel.php';

class Reader
{
	public static function getReader()
	{
		//设置以Excel5格式(Excel97-2003工作簿)
		$mReader = \PHPExcel_IOFactory::createReader('Excel5');
		return $mReader; 
	}
	public static function getCloumn()
	{

	}
	public static function getRow()
	{

	}
	public static function getInfo($file, $sheetnum, $wordtonum=false)
	{
		$mReader = \PHPExcel_IOFactory::createReader('Excel5');
		$PHPExcel = $mReader->load($file);
		$sheet = $PHPExcel->getsheet($sheetnum);
		// 取得总行数
		$highestRow = $sheet->getHighestRow();
		// 取得总列数
		$highestColumm = $sheet->getHighestColumn(); 
		//字母列转换为数字列 如:AA变为27
		$highestColumm = \PHPExcel_Cell::columnIndexFromString($highestColumm);
		for ($row = 2; $row <= $highestRow; $row++)
		{
			//获取用户名
        	//$columnName = \PHPExcel_Cell::stringFromColumnIndex(0);
            $user['u_name'][] = $sheet->getCellByColumnAndRow(0, $row)->getValue();
		}
		//echo $highestColumm;
		return $user;
	}

	public static function import($data)
    {
        $objPHPExcel = new \PHPExcel();
        $objPHPExcel->getProperties()->setCreator("ctos")
            ->setLastModifiedBy("ctos")
            ->setTitle('Office 2007 XLSX Test Document')
            ->setSubject('Office 2007 XLSX Test Document')
            ->setDescription('test')
            ->setKeywords('data from lyon-php')
            ->setCategory('lyon-php');

        $objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('G1', '用户名')
            ->setCellValue('H1', '当前使用用户名')
            ->setCellValue('I1', '性别')
            ->setCellValue('J1', '关注数量')
            ->setCellValue('K1', '粉丝数量')
            ->setCellValue('L1', '微博数量')
            ->setCellValue('M1', '籍贯')
            ->setCellValue('N1', '毕业大学')
            ->setCellValue('O1', '生日')
            ->setCellValue('P1', '注册时间')
            ->setCellValue('Q1', '描述')
            ->setCellValue('R1', '公司');
        //内容
        foreach ($data as $key => $value)
        {
            $objPHPExcel->getActiveSheet(0)->setCellValue('G'. ($value['id'] + 1), $value['u_name']);
            $objPHPExcel->getActiveSheet(0)->setCellValue('H'. ($value['id'] + 1), $value['n_name']);
            $objPHPExcel->getActiveSheet(0)->setCellValue('I'. ($value['id'] + 1), $value['gender']);
            $objPHPExcel->getActiveSheet(0)->setCellValue('J'. ($value['id'] + 1), $value['attention']);
            $objPHPExcel->getActiveSheet(0)->setCellValue('K'. ($value['id'] + 1), $value['fans']);
            $objPHPExcel->getActiveSheet(0)->setCellValue('L'. ($value['id'] + 1), $value['weibo_count']);
            $objPHPExcel->getActiveSheet(0)->setCellValue('M'. ($value['id'] + 1), $value['come_from']);
            $objPHPExcel->getActiveSheet(0)->setCellValue('N'. ($value['id'] + 1), $value['university']);
            $objPHPExcel->getActiveSheet(0)->setCellValue('O'. ($value['id'] + 1), $value['birthday']);
            $objPHPExcel->getActiveSheet(0)->setCellValue('P'. ($value['id'] + 1), $value['register']);
            $objPHPExcel->getActiveSheet(0)->setCellValue('Q'. ($value['id'] + 1), $value['discribe']);
            $objPHPExcel->getActiveSheet(0)->setCellValue('R'. ($value['id'] + 1), $value['company']);
            $objPHPExcel->getActiveSheet()->getRowDimension($value['id'] + 1)->setRowHeight(18);
        }
        $objPHPExcel->setActiveSheetIndex()->setTitle('weibo_goldleaf');
        $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
        $objWriter->save('goldleafwine_full.xls');
    }

    public static function importTmp($data)
    {
        $objPHPExcel = new \PHPExcel();
        $objPHPExcel->getProperties()->setCreator("ctos")
            ->setLastModifiedBy("ctos")
            ->setTitle('Office 2007 XLSX Test Document')
            ->setSubject('Office 2007 XLSX Test Document')
            ->setDescription('test')
            ->setKeywords('data from lyon-php')
            ->setCategory('lyon-php');

        $objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('G1', '用户名')
            ->setCellValue('H1', '当前使用用户名')
            ->setCellValue('I1', '性别')
            ->setCellValue('J1', '关注数量')
            ->setCellValue('K1', '粉丝数量')
            ->setCellValue('L1', '微博数量')
            ->setCellValue('M1', '籍贯')
            ->setCellValue('N1', '毕业大学')
            ->setCellValue('O1', '生日');
        //内容
        foreach ($data as $key => $value)
        {
            $objPHPExcel->getActiveSheet(0)->setCellValue('G'. ($value['id'] + 1), $value['u_name']);
            $objPHPExcel->getActiveSheet(0)->setCellValue('H'. ($value['id'] + 1), $value['n_name']);
            $objPHPExcel->getActiveSheet(0)->setCellValue('I'. ($value['id'] + 1), $value['gender']);
            $objPHPExcel->getActiveSheet(0)->setCellValue('J'. ($value['id'] + 1), $value['attention']);
            $objPHPExcel->getActiveSheet(0)->setCellValue('K'. ($value['id'] + 1), $value['fans']);
            $objPHPExcel->getActiveSheet(0)->setCellValue('L'. ($value['id'] + 1), $value['weibo_count']);
            $objPHPExcel->getActiveSheet(0)->setCellValue('M'. ($value['id'] + 1), $value['come_from']);
            $objPHPExcel->getActiveSheet(0)->setCellValue('N'. ($value['id'] + 1), $value['university']);
            $objPHPExcel->getActiveSheet(0)->setCellValue('O'. ($value['id'] + 1), $value['birthday']);
            $objPHPExcel->getActiveSheet()->getRowDimension($value['id'] + 1)->setRowHeight(18);
        }
        $objPHPExcel->setActiveSheetIndex()->setTitle('青岛大虾');
        $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
        $objWriter->save('shrimp_full.xls');
    }
}